package com.example.android.BluetoothChat.service.impl;

import java.util.Date;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.example.android.BluetoothChat.bean.Game;
import com.example.android.BluetoothChat.bean.GameRequestResponse;
import com.example.android.BluetoothChat.bean.Player;

public class MockDiscoveryServiceImpl extends ADiscoveryService{


	private Thread _mockThread = null;

	public MockDiscoveryServiceImpl(){

	}



	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		super.onStartCommand(intent, flags, startId);
		if(_mockThread == null){

			_mockThread = new Thread() {

				@Override
				public void run() {
					int i = 1;
					while(isStarted()){
						try {
								Thread.sleep(1000*10);
								Player locPlayer = new Player();
								locPlayer.setName("Mock player " + i);
								locPlayer.setBluetoothMacAddress("mac address " + String.valueOf(new Date().getTime()));

								Game locGame = new Game();
								locGame.setName("Mock game " + i++);
								locGame.setId(new Date().getTime());
								fireRequestForPlaying(locPlayer, locGame);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
				}
			};


			_mockThread.start();
		}

		// We want this service to continue running until it is explicitly
		// stopped, so return sticky.
		return START_STICKY;
	}

}
